from django.db import models
from lib.CommonModels import CommonModel
from django.contrib.auth.models import AbstractUser


# 继承用户表和公共表
class UserInfo(AbstractUser, CommonModel):
    '''
    AbstractUser包含用户名、密码、等字段
    CommonModel 包含创建时间和更新时间字段
    '''
    phone = models.BigIntegerField(null=True, verbose_name='联系电话')
    avatar = models.FileField(upload_to='avatar/', verbose_name='头像文件',
                              default='avatar/default.png')
    blog = models.OneToOneField(to='app_blog.Blog', null=True, on_delete=models.CASCADE)
    delete_state = ((False, '存在'), (True, '已删除'))
    is_delete = models.BooleanField(default=False, choices=delete_state, verbose_name='是否已删除')

    class Meta():
        db_table = 'userinfo'
        verbose_name_plural = '用户信息表'

    def __str__(self):
        '''
        为了方便后续的操作可视化
        :return: 用户对象的用户名
        '''
        return f"用户 {self.username}"
